// Source File Name:   CPUnicode.java

package com.vhly.classfile;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

// Referenced classes of package com.vhly.classfile:
//            CPEntry

public class CPUnicode
        extends CPEntry {

    public static final int tag = 2;
    private String value;
    private int data_len;
    private byte buf[];

    public CPUnicode() {
        value = "vhly[FR]";
        try {
            buf = value.getBytes("Unicode");
        }
        catch (UnsupportedEncodingException unsupportedencodingexception) {
            buf = value.getBytes();
        }
        data_len = buf.length;
    }

    public CPUnicode(String s) {
        value = s;
        try {
            buf = value.getBytes("Unicode");
        }
        catch (UnsupportedEncodingException unsupportedencodingexception) {
            buf = value.getBytes();
        }
        data_len = buf.length;
    }

    public String getString() {
        return value;
    }

    public void setString(String s) {
        value = s;
        try {
            buf = value.getBytes("Unicode");
        }
        catch (UnsupportedEncodingException unsupportedencodingexception) {
            buf = value.getBytes();
        }
        data_len = buf.length;
    }

    public void write(DataOutputStream dataoutputstream)
            throws IOException {
        dataoutputstream.write(2);
        dataoutputstream.writeShort(data_len);
        dataoutputstream.write(buf, 0, data_len);
    }

    public void read(DataInputStream datainputstream)
            throws IOException {
        data_len = datainputstream.readUnsignedShort();
        buf = new byte[data_len];
        datainputstream.read(buf, 0, data_len);
        try {
            value = new String(buf, "Unicode");
        }
        catch (UnsupportedEncodingException unsupportedencodingexception) {
            value = new String(buf);
        }
    }

    public int getType() {
        return 2;
    }

    /**
     * 比较指定元素是否和自身相等
     *
     * @param e CPEntry
     * @return 0 equals -1 no
     */
    public boolean equalsTo(CPEntry e) {
        return false;
    }
}